<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>水表日读表记录</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" type="text/css" href="../bootstrap/dist/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/bootstrap-datetimepicker.min.css" />
		<!--<link rel="stylesheet" type="text/css" href="../css/public.css" />-->
	</head>
	<style type="text/css">
		.remove {
			cursor: pointer;
		}
		
		.remove:hover {
			/*color: red;*/
		}
		
		.pagination span {
			font: 14px/34px "";
			padding: 0 5px;
		}
		
		.form-control {
			display: inline-block;
			width: 120px;
		}
		
		.search {
			width: 155px;
		}
		
		.header {
			/*border-bottom: 1px solid #fefefe;*/
		}
		
		.header span {
			padding: 0 5px;
		}
		.table_cla {
			height: 560px;
		}
	</style>

	<body>
		<div id="app" style="width: 100%; margin: 0 auto;padding:0 20px;">
			<div class="header" style="margin-top: 20px;">
				<!--<input class="form-control form_datetime" placeholder="请选择月份" v-model="month_date" type="text" size="16">-->
				<input style="width: 150px;" class="time-input form-control" type="text" id="datetimepicker" v-model="start" placeholder="请选择开始时间">
				<!--<input                       class="time-input form-control" type="text" id="datetimepicker" v-model="start">-->
				<!--<p>{{start}}</p>-->
				<!--<span>结束时间:</span>-->
				<input style="width: 150px;" class="time-input form-control" type="text" id="datetimepicker1" v-model="end" placeholder="请选择结束时间">
				<!--<span>楼宇：</span>-->
				<select name="" class="form-control" v-model="build_model" @change="buildchange">
					<option v-for="index in build" :value="index.id" v-text="index.buildname"></option>
				</select>
				<!--<span>单元：</span>-->
				<select name="" class="form-control" v-model="unit_model" @change="unitchange">
					<option v-for="index in unit" :value="index.id" v-text="index.unitname"></option>
				</select>
				<!--<span>楼层：</span>-->
				<select name="" class="form-control" v-model="floor_model" @change="floorchange">
					<option v-for="index in floor" :value="index.id" v-text="index.floorname"></option>
				</select>
				<!--<span>房号：</span>-->
				<select name="" class="form-control" v-model="room_model">
					<option v-for="index in room" :value="index.rommid" v-text="index.rommcode"></option>
				</select>
				<select name="" class="form-control" v-model="rechresult">
					<option v-for="index in leixing" :value="index.id" v-text="index.name"></option>
				</select>
				<input style="width: 155px;" type="text" class="form-control" name="search1" id="search1" value="" v-model="searchmain" placeholder="请输入水表号或房号" />
				<button type="button" class="btn btn-info" data-dismiss="modal" @click="search">搜索</button>
				<!--<button type="button" class="btn btn-info" data-dismiss="modal" @click="addMensuo">增加</button>-->

			</div>
			<div class="table_cla">
				<table class="table">
				<caption>查询水表日读表记录</caption>
				<thead>
					<tr>
						<th>楼宇名称</th>
						<th>单元号</th>
						<th>楼层</th>
						<th>房间号</th>
						<!--<th>业主</th>-->
						<th>表号 </th>
						<!--<th>创建时间 </th>-->
						<th>读表数 </th>
						<th>日用量</th>
						<th>用量日期</th>						
						<th>最后抄表时间</th>
						<th>结果</th>
						<th>返回说明</th>						
					</tr>
				</thead>
				<tbody>
					<tr v-for="(tt,index) in table">
						<td v-text="tt.buildname"></td>
						<td v-text="tt.units"></td>
						<td v-text="tt.floor"></td>
						<td v-text="tt.rommcode"></td>
						<!--<td v-text="tt.custname"></td>-->
						<td v-text="tt.watchno"></td>						
						<!--<td v-text="tt.createdate"></td>-->
						<td v-text="tt.dosagesum"></td>
						<td v-text="tt.daydosage"></td>
						<td v-text="tt.markday"></td>
						<td v-text="tt.readtime"></td>
						<td v-text="tt.result"></td>
						<td v-text="tt.resultmsg"></td>						
					</tr>
				</tbody>
			</table>
			
			</div>
			<ul class="pagination">
					<span v-text="count_all"></span>
				<!--<li v-show="current != 1" @click="current-- && goto(current--)">
					<a href="#">上一页</a>
				</li>-->
				<li v-for="index in pages" @click="goto(index)" :class="{'active':current == index}" :key="index">
					<a href="#" v-text="index"></a>
				</li>
				<!--<li v-show="allpage != current && allpage != 0 " @click="current++ && goto(current++)">
					<a href="#">下一页</a>
				</li>-->
				<span>跳到:</span>
				<!--<input style="width: 50px;height: 34px;" min="1" max="{{allpage}}" type="number" name="goto" id="goto" v-model="jump" />-->
				<input style="width: 50px;height: 28px;" name="goto" id="goto" v-model="jump" type="text" name="" oninput="value=value.replace(/[^\d]/g,'')">
				
				<span>页</span>
				<button type="button" id="gotoo" @click="goto(jump)" class="btn btn-danger ">确定 </button>
			</ul>
			<!-- 模态框（Modal）提示信息 -->
			<div class="modal fade" id="myModal_tips" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title" id="myModalLabel">提示信息</h4>
						</div>
						<div class="modal-body" id="tips" v-text="tips_modal">

						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						</div>
					</div>
				</div>
			</div>
		</div>

	</body>

</html>
<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstrap/dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/bootstrap-datetimepicker.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/bootstrap-datetimepicker.zh-CN.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/public.js" type="text/javascript" charset="utf-8"></script>
<script>
	//	var urlr = "http://192.168.0.30:8085"
	new Vue({
		el: '#app',
		data: {
			val_te: "",
			urlr: "",
			current: 1,
			month_date: "",
			showItem: 5,
			rechresult: "",
			allpage: "",
			jump: "",
			userid: "",
			show_caozuo: false,
			tips_modal: "",
			areaid: "",
			start: "",
			end: "",
			searchmain: "",
			count_all:'',
			panduan: "",
			token: "",
			merchantid: "",
			leixing: [{
				name: '全部',
				id: ""
			}, {
				name: '成功',
				id: "1"
			}, {
				name: '失败',
				id: "-1"
			}, ],
			leixing_model: "",
			payid: "",
			lou: [{
				buildname: '请选择楼宇',
				id: ""
			}],
			lou_model: "",
			danyuan: [{
				unitname: '请选择单元',
				id: ""
			}],
			danyuan_model: '',
			table: [{

				},

			],
			build: [{
				buildname: '请选择楼宇',
				id: ""
			}],
			build_model: "",
			unit: [{
				unitname: '请选择单元',
				id: ""
			}],
			unit_model: '',
			floor: [{
				floorname: '请选择楼层',
				id: ""
			}],
			floor_model: '',
			room: [{
				rommcode: '请选择房号',
				rommid: ""
			}],

			room_model: '',
		},
		//计算属性
		computed: {

		},
		created: function() {
			var that = this;
			var aa = getUrl();
			that.urlr = aa;
			that.build_model = that.build[0].id;
			that.unit_model = that.unit[0].id;
			that.floor_model = that.floor[0].id;
			that.room_model = that.room[0].rommid;
			that.rechresult = that.leixing[0].id;
		},
		mounted: function() {
			
			var that = this;
			this.lou_model = this.lou[0].id;
			this.danyuan_model = this.danyuan[0].id;
			this.leixing_model = this.leixing[0].id;
			var userid = getUrlParam('userid');
			this.userid = userid;
			var createusername = getUrlParam('realname');
			var merchantid = getUrlParam('merchantid');
			this.merchantid = merchantid;
			var areaid = getUrlParam('areaid');
			this.areaid = areaid;
			var token = getUrlParam('token');
			this.token = token;
			if(userid == null || userid == '') {
				//				alert("用户id不能为空")
				this.tips_modal = "用户id不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			if(createusername == null || createusername == '') {
				//				alert("用户姓名不能为空");
				this.tips_modal = "用户姓名不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			if(areaid == null || areaid == '') {
				//				alert("小区id不能为空");
				this.tips_modal = "小区id不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			if(merchantid == null || merchantid == '') {
				//				alert("物业id不能为空");
				this.tips_modal = "物业id不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			//日期初始化
			this.datePickerInit();
			that.build_model = that.build[0].id;
			that.unit_model = that.unit[0].id;
			that.floor_model = that.floor[0].id;
			that.room_model = that.room[0].rommid;
			var datainit = {
				pagenumber: 1,
				pagesize: 10,
				areaid: this.areaid,
				buildid: this.build_model,
				unitid: this.unit_model,
				rommid: this.room_model,
				floor: this.floor_model,
				selectinfo: this.searchmain,
				startday: this.start,
				endday: this.end,				
				result: this.rechresult
			};
			if(this.val_te != true) {
				this.jiazai(datainit);
				this.lou_info(this.areaid)
				this.table = ""
			}

		},
		computed: {
			pages: function() {
				var pag = [];
				if(this.current < this.showItem) { //如果当前的激活的项 小于要显示的条数
					//总页数和要显示的条数那个大就显示多少条
					var i = Math.min(this.showItem, this.allpage);
					while(i) {
						pag.unshift(i--);
					}
				} else { //当前页数大于显示页数了
					var middle = this.current - Math.floor(this.showItem / 2), //从哪里开始
						i = this.showItem;
					if(middle > (this.allpage - this.showItem)) {
						middle = (this.allpage - this.showItem) + 1
					}
					while(i--) {
						pag.push(middle++);
					}
				}
				return pag
			},
		},
		methods: {
			datePickerInit: function() {
				//debugger
				var d, s;
				var self = this;
				self.start = s;
				$('#datetimepicker').datetimepicker({
					minView: "month", //选择日期后，不会再跳转去选择时分秒 
					language: 'zh-CN',
					format: 'yyyy-mm-dd',
					todayBtn: 1,
					autoclose: 1,
				});
				$('#datetimepicker1').datetimepicker({
					startDate: s,
					minView: "month", //选择日期后，不会再跳转去选择时分秒 
					language: 'zh-CN',
					format: 'yyyy-mm-dd',
					todayBtn: 1,
					autoclose: 1,
				});
				$('#datetimepicker').datetimepicker()
					.on('hide', function(ev) {
						var value = $("#datetimepicker").val();
						self.start = value;
						$('#datetimepicker1').datetimepicker('setStartDate', self.start);
						self.end = "";
					});
				$('#datetimepicker1').datetimepicker()
					.on('hide', function(ev) {
						var value = $("#datetimepicker1").val();
						self.end = value;

					});
			},//获取楼宇
			lou_info: function(areaid) {
				var that = this;
				var data = JSON.stringify({
					parentid: that.areaid
				})
				$.ajax({
					contentType: "application/json; charset=utf-8",
					type: "POST",
					url: that.urlr + "/public/selectBuildList",
					data: data,
					async: true,
					dataType: "json",
					success: function(msg) {
						//						console.log(msg);
						if(msg.code == 200) {
							var aa = JSON.parse(msg.returnString);
							var te = {
								buildname: '请选择楼宇',
								id: ""
							}
							aa.unshift(te);
							that.build = aa;
							that.build_model = that.build[0].id;
						} else {
							//							alert(msg.disp)
							that.tips_modal = msg.disp;
							$('#myModal_tips').modal('show');
						}
					},
					error: function() {
						//						alert("获取信息失败");
						that.tips_modal = "获取信息失败";
						$('#myModal_tips').modal('show');
					}
				});
			},

			//楼改变请求单元
			buildchange: function() {
				this.unil_info(this.build_model);
			},
			//获取单元
			unil_info: function(areaid) {
				if(areaid != "") {
					var that = this;
					var data = JSON.stringify({
						parentid: areaid
					})
					$.ajax({
						contentType: "application/json; charset=utf-8",
						type: "POST",
						url: that.urlr + "/public/selectUnitsList",
						data: data,
						async: true,
						dataType: "json",
						success: function(msg) {
							//							console.log(msg);
							if(msg.code == 200) {
								var aa = JSON.parse(msg.returnString);
								var te = {
									unitname: '请选择单元',
									id: ""
								}
								aa.unshift(te);
								that.unit = aa;
								that.unit_model = that.unit[0].id;
							} else {
								//							alert(msg.disp)
								that.tips_modal = msg.disp;
								$('#myModal_tips').modal('show');
							}
						},
						error: function() {
							//						alert("获取信息失败");
							that.tips_modal = "获取信息失败";
							$('#myModal_tips').modal('show');
						}
					});
				}

			},
			/*单元改变*/
			unitchange: function() {
				this.floor_info(this.unit_model);
			},
			//获取楼层
			floor_info: function(areaid) {
				if(areaid != "") {
					var that = this;
					var data = JSON.stringify({
						parentid: areaid
					})
					$.ajax({
						contentType: "application/json; charset=utf-8",
						type: "POST",
						url: that.urlr + "/public/selectFloors",
						data: data,
						async: true,
						dataType: "json",
						success: function(msg) {
							//							console.log(msg);
							if(msg.code == 200) {
								var aa = JSON.parse(msg.returnString);
								var te = {
									floorname: '请选择楼层',
									id: ""
								}
								var flloor = [];
								for(var i = 1; i <= aa; i++) {
									var main = {
										floorname: i + "层",
										id: i
									}
									flloor.push(main)
								}
								flloor.unshift(te);
								that.floor = flloor;
								that.floor_model = that.floor[0].id;
							} else {
								//							alert(msg.disp)
								that.tips_modal = msg.disp;
								$('#myModal_tips').modal('show');
							}
						},
						error: function() {
							//						alert("获取信息失败");
							that.tips_modal = "获取信息失败";
							$('#myModal_tips').modal('show');
						}
					});
				}

			},
			//楼层改变
			floorchange: function() {
//				this.room_info(this.unit_model, this.floor_model);
				var that = this;
				if(this.unit_model == '' || this.floor_model == '') {
					var aa = [];
					var te = {
						rommcode: '请选择房号',
						rommid: ""
					}
					aa.unshift(te);
					that.room = aa;
					that.room_model = that.room[0].rommid;
				} else {
					this.room_info(this.unit_model, this.floor_model);
				}
			},
			//出现房屋
			room_info: function(areaid, floor_c) {
				if(areaid != "" || floor_c != "") {
					var that = this;
					var data = JSON.stringify({
						parentid: areaid,
						floor: floor_c
					})
					$.ajax({
						contentType: "application/json; charset=utf-8",

						type: "POST",
						url: that.urlr + "/public/selectRoomCodeList",
						data: data,
						async: true,
						dataType: "json",
						success: function(msg) {
//							debugger
							//							console.log(msg);
							if(msg.code == 200) {
								var aa = JSON.parse(msg.returnString);
								var te = {
									rommcode: '请选择房号',
									rommid: ""
								}
								aa.unshift(te);
								that.room = aa;
								that.room_model = that.room[0].rommid;
							} else {
								that.tips_modal = msg.disp;
								$('#myModal_tips').modal('show');
							}
						},
						error: function() {
							that.tips_modal = "获取信息失败";
							$('#myModal_tips').modal('show');
						}
					});
				}
			},
			//加载数据
			jiazai: function(e) {
//				console.log(e)
				var data = JSON.stringify(e);
				var that = this;
				$.ajax({
					contentType: "application/json; charset=utf-8",
					type: "POST",
					url: that.urlr + "/verify/watermeter/selectWaterDayRead",
					data: data,
					headers: {
						"userid": that.userid,
						"token": that.token
					},
					async: true,
					dataType: "json",
					success: function(msg) {						
//						console.log(msg);
						if(msg.code == 200) {
							var data = JSON.parse(msg.returnString);
							//							console.log(data);

							for(var i = 0; i < data.length; i++) {
								if(data[i].result == 1) {
									data[i].result = "成功"
								} else if(data[i].result == -1) {
									data[i].result = "失败"
								}
							}
							that.table = data;
							that.count_all = "共" + msg.count + "条";							
							var yu = msg.count % 10;
							if(yu == 0) {
								that.allpage = parseInt(msg.count / 10);
							} else {
								that.allpage = parseInt(msg.count / 10) + 1;
							}

						} else {
							that.tips_modal = msg.disp;
							$('#myModal_tips').modal('show');
						}
					},
					error: function() {
						//						alert("获取信息失败");
						that.tips_modal = "获取信息失败";
						$('#myModal_tips').modal('show');
					}
				});

			},

			goto: function(index) {				
				if(index == this.current) return;
				if(index > this.allpage) {
					return
				}
				//				debugger
				var re = /^[1-9]+[0-9]*]*$/ //判断正整数      // /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字  
				if(!re.test(index)) {
					return false;
				}
				this.current = index;
				var datainit = {
					pagenumber: index,
					pagesize: 10,
					areaid: this.areaid,
					buildid: this.build_model,
					unitid: this.unit_model,
					rommid: this.room_model,
					floor: this.floor_model,
					selectinfo: this.searchmain,
					startday: this.start,
					endday: this.end,
					result: this.rechresult
				};
				this.jiazai(datainit);
				//这里可以发送ajax请求
			},
			search: function() {				
				var that = this;
				var datainit = {
					pagenumber: 1,
					pagesize: 10,
					areaid: that.areaid,
					buildid: that.build_model,
					unitid: that.unit_model,
					rommid: that.room_model,
					floor: that.floor_model,
					selectinfo: that.searchmain,
					startday: that.start,
					endday: that.end,
					result: that.rechresult
				}
				if(that.val_te != true) {
					that.jiazai(datainit);
					that.current=1;
				} else {
					//					alert("非法登录");
					that.tips_modal = "非法登录";
					$('#myModal_tips').modal('show');
				}
			},
		},
	})
</script>